// myPages/wish/wish.js
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var user = require('../../services/user.js');
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userCollect:[]  //用户收藏信息
  },
  
   /** 跳转到导师详情页面 */
  goToTeacher: function (e) {
    if (e.currentTarget.dataset.id != undefined) {
      wx.navigateTo({
        url: '../../myPages/teacher/teacher?teacherId=' +  e.currentTarget.dataset.id
      })
    }
  },

  //查询用户收藏信息
  getCollectInfo() {
    var that = this;
    var userId = wx.getStorageSync('userInfo').id //获取用户id
    let searchCondition = {
      pageSize: 5,
      pageNum: 1,
      conditionList: [],
      sort: {}
    };
    let condition = {
      operator: 1,
      code: 'userId',
      value: userId,       //用户ID
      type: 'Number'
    };
    searchCondition.conditionList.push(condition)

    util.request(api.SelectCollect, searchCondition, 'POST', true).then(function (res) {
      if (res.code === 200) {
        console.log(res.result)
        // //设置介绍文字
        res.result.forEach((value, index, arr) => {
          let userEducationExperiencesTXT = "";
          for (let i in value.userEducationExperiences) {
            if (i == value.userEducationExperiences.length - 1) {
              userEducationExperiencesTXT += value.userEducationExperiences[i].college
            } else {
              userEducationExperiencesTXT += value.userEducationExperiences[i].college + " | "
            }
          }
          value.userEducationExperiencesTXT = userEducationExperiencesTXT.substring(0, userEducationExperiencesTXT.length)
          userEducationExperiencesTXT = "";
        })
       
        that.setData({
          userCollect: res.result
        });
      }
    });
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //接收传过来的参数
    console.log('接收到的userId为：' + options.userid);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getCollectInfo();
    wx.hideShareMenu();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})